This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - File checkout from IOM

scottmahr - Thursday, December 16, 2010 1:13 PM:

Hi, I am trying to download many files from many parts from a c# program on the client.  Below is some code to test downloading a file, but I get an error.  I am able to use attachPhysicalFile no problem to upload files from the same program.  

 

Item myfiles = myInnovator.newItem("File", "get");
Item result1 = myfiles.apply();
Item nfiles = result1.getItemsByXPath("//Item[@type='File']");
 
int fcount = nfiles.getItemCount();
for (int i = 0; i < fcount; i++) {
   Item file = nfiles.getItemByIndex(i);
   Item result = file.checkout("c:\");
   if (result.isError()) {
        Console.WriteLine(string.Format("Failed to checkout file '{0}'", file.getProperty("filename")));
   }
}
 
As I step through the program, fcount equals 989.  Getting the file item seems to work.  My code returns an error at the "checkout" line, and never gets to the error handling if statement. My error message says  “The remote server returned an error: (404) Not Found.”
 
Please let me know if this raises any flags.  
 
Thanks,
 
Scott



dstephen - Thursday, December 16, 2010 2:07 PM:

Hi Scott,

I can't see anything right off the bat but I believe that you can only run a checkout from a client side method and that would mean it needs to be in javascript.  I have similar code using javascript from an Innovator client and it works fine.

Don



souheil - Thursday, December 16, 2010 4:11 PM:

Hi Scott,

 

Try to check security on the c:\ drive.  Change the path to another folder that you have write access to.

 

souheil

 



scottmahr - Thursday, December 16, 2010 2:11 PM:

Thanks Don, my C# is written in VS and compiles to its own program.  It is an executable and is completely separated from the Aras interface.  I feel like that should still work, does that make sense?



scottmahr - Thursday, December 16, 2010 4:44 PM:

Thanks Guys, 

Pretty sure I have write access to c:\, but I changed it to something else just to make sure.

I can check out files fine through the standard client.

I have only one vault set up, and I am able to load files into it using attachPhysicalFile, I think that means it is set up correctly.

I am not sure about vault security, and not completely sure where to go to check that.  

 

I realized that maybe I don't need to be checking out these files.  All I need to do is download them to my client machine.  Is there any other automated way to do this?  I need to hack something together today if at all possible.

 

Thanks for all the help so far,

 

Scott



RobMcAveney - Thursday, December 16, 2010 2:40 PM:

Scott -

I just tested your code here and it seems to work fine.  Not sure what the problem is, but there must be a configuration difference between your environment and mine.  Are you able to check out these files using the standard client?  Do you have multiple vaults set up?  Are all vault servers accessible from the client machine?  Vault security perhaps?

Rob



dstephen - Friday, December 17, 2010 8:20 AM:

Hi Scott,

The javascript below is run within the Innovator environment and it works.  It's not exactly what you want but might provide some help.  Also, I put together a small script to run from a web page to open *.pdf files from the Innovator vault.  Here's a snip of the relevant code:

 ///// ///// ///// /////snip from an html page ///// ///// ///// ///// /////

at this point the connection is established. 

var qry = myI.newItem("Document","get");
      qry.setProperty("item_number",docNum);
      var rel = myI.newItem("Document File", "get");
      rel.setAttribute("select","related_id");
      qry.addRelationship(rel);
      var relfiles = myI.newItem("File","get");
      relfiles.setAttribute("select","id,filename");
      rel.setRelatedItem(relfiles);
      var rslt = qry.apply();
      if (rslt.isError()){
         document.write(rslt.getErrorDetail());
         return;     
      }
      var pdfFiles = rslt.getItemsByXPath("//Item[@type='File']");
      var pdfCount = pdfFiles.getItemCount();
      if (pdfCount > 1){
        document.write("more than one file");
        return;
      }
      if (pdfCount < 1){
        document.write("can't find file");
        return;     
      }
      var fileID = pdfFiles.getItemByIndex(0).getProperty("id");
      var fileName = pdfFiles.getItemByIndex(0).getProperty("filename");
      vaultURL = vaultURL + "?dbName=" + db + "&fileID=" + fileID + "&fileName=" + fileName;
      //alert(vaultURL);
      window.open(vaultURL);

 ///// ///// ///// /////  java from within Innovator  ///// ///// ///// ///// ///// /////

var myI = new Innovator();
var rootPath = "C:\Temp\";
var i;
var j;
var msg = "Done";
/*
Set up the query for all the Manuf Doc Items with attached files of man_doc_type1= program.

Most of the information is in the docFile relationship but need the parent to get
the state = active information
*/
var qryItem = this.newItem("Manufacturing Doc","get");
qryItem.setAttribute("select","item_number,state,description");
qryItem.setProperty("state","Active");

var docFiles = this.newItem("Manufacturing Doc File","get");
docFiles.setAttribute("select","man_doc_type1,man_doc_type2,man_doc_status,related_id(checkout_path, filename)");
docFiles.setProperty("man_doc_type1","program");
docFiles.setProperty("man_doc_status","Active");
qryItem.addRelationship(docFiles);

var results = qryItem.apply();
if (results.isError()) {
    top.aras.AlertError(results.getErrorDetail());
    return;
}

/*
Now results has all the manufacturing documents with only program files attached.
Must select only the active BVR Manufacturing Docs(may be redundant w/query).  Then run through the relationship and
checkout each of the program files.
*/
var docList = results.getItemsByXPath("//Item/Relationships/Item[@type='Manufacturing Doc File']");
var count = docList.getItemCount();
var thisDocRels;
var relsCount;
var relFile;
var relFileFolder;
var relFileState;
var fileItem;
var mfgFile;
var chkResult;
for(i=0; i<count; i++) {
 var thisDoc = docList.getItemByIndex(i);
 relFileState = thisDoc.getProperty("man_doc_status");
 if(relFileState =="Active") {
  relFileFolder = thisDoc.getProperty("man_doc_type2");
  fileItem = thisDoc.getItemsByXPath("related_id/Item[@type='File']");
  mfgFile = fileItem.getItemByIndex(0);
  chkResult = mfgFile.checkout(rootPath + relFileFolder);
  if (chkResult.isError()) {
   top.aras.AlertError("Couldn't save " + mfgFile.getProperty("filename") +" " + chkResult.getErrorDetail());
   return;
  }
 }
}
return msg;



souheil - Thursday, December 16, 2010 5:50 PM:

Here is a VBScript code that is tested.  If you are using windows machine cut and paste the code below.  Make sure you have registered the IOM.dll. To register the IOM.dll do the following:

Open a DOS cmd as an admin. and type regasm IOM.dll /tlb.  Find regasm.exe on your machine.

CODE: Note that files of the same name will be overwritten.
=========
'----------------------------------------------------------------------------'
' VB Script Document
' option explicit
' souheil c karam
' http://www.sckassociates.com
' the Business of PLM
'-----------------------------------------------------------------------------'
'
Dim url  : url = "localhost/.../InnovatorServer.aspx"
Dim db   : db = "InnovatorSolutions"
Dim user : user = "Admin"
Dim password : password = "innovator"
Dim factory
Dim conn, inn
'-------------------------------------------------------------------------'
Sub inv_login()
set factory = CreateObject("Aras.IOM.IomFactory.9.2")
Set conn = factory.CreateHttpServerConnection(url, db, user, password)
Dim login_result
Set login_result = conn.Login
If login_result.IsError Then
  MsgBox "Failed to login"
  Exit Sub
End If
Set inn = factory.CreateInnovator(conn)
End Sub     
'------------------------------------------------------------------------'
Function checkOutFiles(toFolder)
   if ( len(toFolder) = 0 ) then
     toFolder = "c:\myfilecabinet\"
   end if
    
   set queryItem = inn.newItem()
   queryItem.setType("File")
   queryItem.setAction("get")
   queryItem.setAttribute "select","filename,id,checkedout_path"
   set resultItem = queryItem.apply()
   outFile.WriteLine resultItem.ToString()
   if (resultItem.IsError() = False ) then
      n = resultItem.getItemCount()
      Msgbox("Number of items found: " & resultItem.getItemCount())
      for i=0 to n-1
         set item = resultItem.getItemByIndex(i)
        item.checkout toFolder     
      next
   else
      msgbox(resultItem.GetErrorDetail())
   end if 
End Function
'------------------------------------------------------------------------'

                                            
Dim fso, outFile, toFolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.xml", True)
'
toFolder = "c:\myfolder\"
call inv_login()
call checkOutFiles(toFolder)
' clean up'
outFile.close()
MsgBox ("complete")